result = {}
-- INPUT
function result:Input(playAgain, viewLadder) end
-- OUTPUT
function result:Show() end -- show dialog
function result:Hide() end -- hide dialog

----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------

result.layer = nil
result.parent = nil

function result:Input(playAgain, viewLadder)
    self.playAgain = playAgain
    self.viewLadder = viewLadder
end

function result:PlayAgain()
    self:Hide()
    self.playAgain()
end

function result:ViewLadder()
    self:Hide()
    self.viewLadder()
end

function result:Create()
    self.layer = CCLayer:create();
    
    local bg = CCSprite:create("png/result.png");
    bg:setPosition(pplCfg.RESOLUTION.width/2, pplCfg.RESOLUTION.height/2);
    self.layer:addChild(bg);

    local function PlayAgain()
        self:PlayAgain();
    end

    local function ViewLadder()
        self:ViewLadder()
    end

    local item1 = CCMenuItemImage:create("png/playAgain1.png", "png/playAgain2.png")
    item1:registerScriptTapHandler(PlayAgain)
    item1:setPosition(0, 100);

    local item2 = CCMenuItemImage:create("png/viewLadder1.png", "png/viewLadder2.png")
    item2:registerScriptTapHandler(ViewLadder)
    item2:setPosition(0, -100);

    local menu = CCMenu:create()
    menu:addChild(item1)
    menu:addChild(item2)
    self.layer:addChild(menu)

    self.parent:addChild(self.layer, 1)
end

function result:Show()
    self.parent = GetMainScene()
    if (self.layer == nil) then
        self:Create()
    end
    self.layer:setVisible(true)

    -- animation
    self.layer:setScale(0)
    local ac = CCScaleTo:create(0.4, 1.0, 1.0)
    self.layer:runAction(ac)
end

function result:Hide()
    if self.layer then
        self.layer:setVisible(false)
    end
end